package domain.lexicalAnalyzerGenerator;

import domain.grammar.ExtendedTerminalSymbol;

public class MatchInstruction extends Instruction {

	private String terminalSymbolName;
	public MatchInstruction(ExtendedTerminalSymbol extendedTerminalSymbol) {
		terminalSymbolName = extendedTerminalSymbol.getName();
	}

	public String generateCode()
	{
		String code = "";

		code += "if (!grammarStringHelper.matchCurrentToken('" + terminalSymbolName + "')){\n";
		code += "	System.out.println(\"El simbolo actual no corresponde con el simbolo esperado:'" 
			+ terminalSymbolName + "'.\");\n";
		code += "	System.out.println();\n";
		code += "	System.out.println(grammarStringHelper.getCurrentTokenInfo());\n";
		code += "	throw new ParseFailedException();\n";
		code += "}\n";
		code += "try {\n";
		code += "   grammarStringHelper.MoveToken();\n";
		code += "} catch (GrammarStringHelperException e) {\n";
		code += "   e.printStackTrace();\n";
		code += "	throw new ParseFailedException();\n";
		code += "}\n";

		return code;
	}	
}
